/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 *
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0 2010-12-29 上午11:01:15
 *
 * ActiveAccountAction.java 
 *
 *
 *******************************************************************/
package com.transer.web.action.passport;

import com.transer.console.ConsoleConstants;
import com.transer.job.UpdateUserJob;
import com.transer.persistance.bean.User;
import com.transer.persistance.dao.IUserDao;
import com.transer.utils.JobQueueOB;
import com.transer.web.action.TranserActionSupport;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class ActiveAccountAction extends TranserActionSupport {
	private static final long serialVersionUID = -269873165452764211L;
	/** 激活邮箱 */
	private String email;
	/** 激活码 */
	private String code;
	/** 数据库操作 */
	private IUserDao userDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// 根据EMAIL获取用户
		User user = userDao.isEmailExsit(email);
		// 如果用户不存在或者已经激活
		// 激活码不正确,激活失败
		if (user == null || user.isActive() || !user.getActiveCode().equals(code)) {
			// 激活失败
			addFieldError("error.active", getText("error.active"));
			return TranserActionSupport.INPUT;
		}
		// 设置激活状态
		user.setActive(true);
		// 清空激活码
		user.setActiveCode("");
		// 保存用户
		JobQueueOB.getInstance().addJob(ConsoleConstants.QUEUE_INDEX_SAVE_USER, new UpdateUserJob(userDao, user));
		// 激活成功
		return TranserActionSupport.SUCCESS;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
}